#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/wait.h>

pid_t pid;

void fun_1(int num){
  if(num == SIGINT){
    kill(getppid(),SIGUSR1);
  }else if(num == SIGQUIT){
    kill(getppid(),SIGUSR2);
  }else if(num == SIGUSR1){
    printf("all get off the bus\n");
    exit(0);
  }
}

void fun_2(int num){
  if(num == SIGUSR1){
    printf("move to next station\n");
  }else if(num == SIGUSR2){
    printf("stop the bus\n");
  }else if(SIGTSTP == num){
    kill(pid,SIGUSR1);
  }
}

int main(int argc,char* argv[]){
  pid = fork();

  if(pid > 0){
    printf("parent pid is %d,child pid is %d\n",getpid(),pid);
    signal(SIGUSR1,fun_2);
    signal(SIGUSR2,fun_2);
    signal(SIGTSTP,fun_2);
  }else if(pid == 0){
    signal(SIGINT,fun_1);
    signal(SIGQUIT,fun_1);
    signal(SIGUSR1,fun_1);
    while(1)
      pause();
  }
  if(pid > 0)
    wait(NULL);

  return 0;
}
